

/**
 * 导出所有 后台的接口 给 index.js 文件注册
 */

const router = require('koa-router');
const rate = require("./router-classify/rate") // 费率的接口
const file = require("./router-classify/file")  // 上传文件的接口
const qa = require("./router-classify/qa")  // 上传文件的接口
const buy = require("./router-classify/buy")  // 上传文件的接口
const product = require("./router-classify/product")  // 上传文件的接口

let myRouter = new router();


registerApi(rate)
registerApi(file)
registerApi(qa)
registerApi(buy)
registerApi(product)

function registerApi(data) {

    for (let method in data) {

        let item = data[method];

        for (let api_name in item) {

            let callback = item[api_name];

            api_name="/"+api_name

            if (Array.isArray(callback)) {
                let arg = [api_name, ...callback];
                myRouter[method].apply(myRouter, arg)
            } else {
                myRouter[method](api_name, callback)
            }
        }
    }
}




module.exports= myRouter
